package com.csi.controller.history;

import com.alibaba.fastjson2.JSON;
import com.csi.domain.History;
import com.csi.domain.Permission;
import com.csi.pojo.Result;
import com.csi.service.HistoryService;
import com.csi.service.PermissionService;
import com.csi.service.impl.HistoryServiceImpl;
import com.csi.service.impl.PermissionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * 查询用户的全部历史记录
 */
@WebServlet("/history/queryAllController")
public class QueryAllController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        String userNumber = req.getParameter("userNumber");

        HistoryService historyService = new HistoryServiceImpl();

        List<History> histories = historyService.queryAll(userNumber);

        Result<List<History>> result = new Result<>();

        result.setCode(200);
        result.setMsg("success");
        result.setDatas(histories);

        out.print(JSON.toJSONString(result));
        out.flush();
        out.close();
    }
}
